theme(axis.ticks.x=element_blank()) +
theme(axis.text.x=element_blank())
ggplot(data = PandP, aes(x = linenumber, y = sentiment, fill = method)) +
geom_bar(stat = "identity") +
facet_wrap(~method, nrow = 3) +
theme_minimal() +
ylab("Sentiment") +
labs(title = expression(paste("Sentiment in ", italic("Pride and Prejudice"))),
caption = caption) +
geom_label(data = annotatetext, aes(x, y, label=label), hjust = 0.5,
label.size = 0, size = 3, color="#2b2b2b", inherit.aes = FALSE) +
geom_segment(data = annotatetext, aes(x = x, y = y1, xend = x, yend = y2),
arrow = arrow(length = unit(0.05, "npc")), inherit.aes = FALSE) +
scale_fill_viridis(end = 0.4, discrete=TRUE) +
scale_x_discrete(expand=c(0.01,0)) +
theme(strip.text=element_text(hjust=0)) +
theme(axis.text.y=element_text(margin=margin(r=-10))) +
theme(plot.caption=element_text(size=9)) +
theme(legend.position="none") +
theme(axis.title.x=element_blank()) +
theme(axis.ticks.x=element_blank()) +
theme(axis.text.x=element_blank())
dev.off()
ggplot(data = PandP, aes(x = linenumber, y = sentiment, fill = method)) +
geom_bar(stat = "identity") +
facet_wrap(~method, nrow = 3) +
theme_minimal() +
ylab("Sentiment") +
labs(title = expression(paste("Sentiment in ", italic("Pride and Prejudice"))),
caption = caption) +
geom_label(data = annotatetext, aes(x, y, label=label), hjust = 0.5,
label.size = 0, size = 3, color="#2b2b2b", inherit.aes = FALSE) +
geom_segment(data = annotatetext, aes(x = x, y = y1, xend = x, yend = y2),
arrow = arrow(length = unit(0.05, "npc")), inherit.aes = FALSE) +
scale_fill_viridis(end = 0.4, discrete=TRUE) +
scale_x_discrete(expand=c(0.01,0)) +
theme(strip.text=element_text(hjust=0)) +
theme(axis.text.y=element_text(margin=margin(r=-10))) +
theme(plot.caption=element_text(size=9)) +
theme(legend.position="none") +
theme(axis.title.x=element_blank()) +
theme(axis.ticks.x=element_blank()) +
theme(axis.text.x=element_blank())
#Define labels and annotations for the plot
PP_sentiment <- process_sentiment(prideprejudice, "bing")
PandPannot <- data.frame(x = c(243, 518, 747, 1005), y = rep(14.9, 4),
label = c("Ball at Netherfield", "Mr. Darcy proposes",
"Lydia elopes", "Mr. Darcy proposes again"),
y1 = rep(13.5, 4), y2 = c(8.5, 7.5, 7.5, 8.5))
#Plot results
p <- plot_sentiment(PP_sentiment, PandPannot)
p + labs(title = expression(paste("Sentiment in ", italic("Pride and Prejudice"))))
PP_sentiment <- process_sentiment(prideprejudice, "afinn")
PandPannot <- data.frame(x = c(243, 518, 747, 1005), y = rep(14.9, 4),
label = c("Ball at Netherfield", "Mr. Darcy proposes",
"Lydia elopes", "Mr. Darcy proposes again"),
y1 = rep(13.5, 4), y2 = c(8.5, 7.5, 7.5, 8.5))
#Plot results
p <- plot_sentiment(PP_sentiment, PandPannot)
p + labs(title = expression(paste("NRC Sentiment in ", italic("Pride and Prejudice"))))
PP_sentiment <- process_sentiment(prideprejudice, "afinn")
PandPannot <- data.frame(x = c(243, 518, 747, 1005), y = rep(24.9, 4),
label = c("Ball at Netherfield", "Mr. Darcy proposes",
"Lydia elopes", "Mr. Darcy proposes again"),
y1 = rep(13.5, 4), y2 = c(8.5, 7.5, 7.5, 8.5))
#Plot results
p <- plot_sentiment(PP_sentiment, PandPannot)
p + labs(title = expression(paste("NRC Sentiment in ", italic("Pride and Prejudice"))))
PP_sentiment <- process_sentiment(prideprejudice, "afinn")
PandPannot <- data.frame(x = c(243, 518, 747, 1005), y = rep(34.9, 4),
label = c("Ball at Netherfield", "Mr. Darcy proposes",
"Lydia elopes", "Mr. Darcy proposes again"),
y1 = rep(13.5, 4), y2 = c(8.5, 7.5, 7.5, 8.5))
#Plot results
p <- plot_sentiment(PP_sentiment, PandPannot)
p + labs(title = expression(paste("NRC Sentiment in ", italic("Pride and Prejudice"))))
PP_sentiment <- process_sentiment(prideprejudice, "afinn")
PandPannot <- data.frame(x = c(243, 518, 747, 1005), y = rep(34.9, 4),
label = c("Ball at Netherfield", "Mr. Darcy proposes",
"Lydia elopes", "Mr. Darcy proposes again"),
y1 = rep(25.5, 4), y2 = c(8.5, 7.5, 7.5, 8.5))
p <- plot_sentiment(PP_sentiment, PandPannot)
p + labs(title = expression(paste("NRC Sentiment in ", italic("Pride and Prejudice"))))
PP_sentiment <- process_sentiment(prideprejudice, "afinn")
PandPannot <- data.frame(x = c(243, 518, 747, 1005), y = rep(34.9, 4),
label = c("Ball at Netherfield", "Mr. Darcy proposes",
"Lydia elopes", "Mr. Darcy proposes again"),
y1 = rep(35.5, 4), y2 = c(8.5, 7.5, 7.5, 8.5))
#Plot results
p <- plot_sentiment(PP_sentiment, PandPannot)
p + labs(title = expression(paste("NRC Sentiment in ", italic("Pride and Prejudice"))))
PP_sentiment <- process_sentiment(prideprejudice, "afinn")
PandPannot <- data.frame(x = c(243, 518, 747, 1005), y = rep(34.9, 4),
label = c("Ball at Netherfield", "Mr. Darcy proposes",
"Lydia elopes", "Mr. Darcy proposes again"),
y1 = rep(35.5, 4), y2 = c(5.5, 5.5, 5.5, 5.5))
#Plot results
p <- plot_sentiment(PP_sentiment, PandPannot)
p + labs(title = expression(paste("NRC Sentiment in ", italic("Pride and Prejudice"))))
PP_sentiment <- process_sentiment(prideprejudice, "afinn")
PandPannot <- data.frame(x = c(243, 518, 747, 1005), y = rep(34.9, 4),
label = c("Ball at Netherfield", "Mr. Darcy proposes",
"Lydia elopes", "Mr. Darcy proposes again"),
y1 = rep(35.5, 4), y2 = c(25.5, 25.5, 25.5, 25.5))
#Plot results
p <- plot_sentiment(PP_sentiment, PandPannot)
p + labs(title = expression(paste("NRC Sentiment in ", italic("Pride and Prejudice"))))
PP_sentiment <- process_sentiment(prideprejudice, "afinn")
PandPannot <- data.frame(x = c(243, 518, 747, 1005), y = rep(34.9, 4),
label = c("Ball at Netherfield", "Mr. Darcy proposes",
"Lydia elopes", "Mr. Darcy proposes again"),
y1 = rep(34.5, 4), y2 = c(25.5, 25.5, 25.5, 25.5))
#Plot results
p <- plot_sentiment(PP_sentiment, PandPannot)
p + labs(title = expression(paste("NRC Sentiment in ", italic("Pride and Prejudice"))))
PP_sentiment <- process_sentiment(prideprejudice, "afinn")
PandPannot <- data.frame(x = c(243, 518, 747, 1005), y = rep(34.9, 4),
label = c("Ball at Netherfield", "Mr. Darcy proposes",
"Lydia elopes", "Mr. Darcy proposes again"),
y1 = rep(34.5, 4), y2 = c(25.5, 20.5, 20.5, 20.5))
#Plot results
p <- plot_sentiment(PP_sentiment, PandPannot)
p + labs(title = expression(paste("NRC Sentiment in ", italic("Pride and Prejudice"))))
(out <- with(
presidential_debates_2012,
sentiment_by(
get_sentences(dialogue),
list(person, time)
)
))
presidential_debates_2012 %>%
dplyr::mutate(dialogue_split = get_sentences(dialogue)) %$%
sentiment_by(dialogue_split, list(person, time))
presidential_debates_2012 %>%
dplyr::mutate(dialogue_split = get_sentences(dialogue)) %>%
sentiment_by(dialogue_split, list(person, time))
presidential_debates_2012 %>%
dplyr::mutate(dialogue_split = get_sentences(dialogue)) %$%
sentiment_by(dialogue_split, list(person, time))
library(magrittr)
presidential_debates_2012 %>%
dplyr::mutate(dialogue_split = get_sentences(dialogue)) %$%
sentiment_by(dialogue_split, list(person, time))
## Load Packages
library(quanteda)
library(quanteda.corpora)
library(readr)
library(syuzhet)
library(sentimentr)
library(ggplot2)
library(janeaustenr)
library(viridis)
library(magrittr)
presidential_debates_2012 %>%
dplyr::mutate(dialogue_split = get_sentences(dialogue)) %$%
sentiment_by(dialogue_split, list(person, time))
out<-presidential_debates_2012 %>%
dplyr::mutate(dialogue_split = get_sentences(dialogue)) %$%
sentiment_by(dialogue_split, list(person, time))
plot(out)
plot(uncombine(out))
View(out)
out<-presidential_debates_2012 %>%
dplyr::mutate(dialogue_split = get_sentences(dialogue)) %$%
sentiment_by(dialogue_split, list(person))
plot(out)
speaker<-presidential_debates_2012 %>%
dplyr::mutate(dialogue_split = get_sentences(dialogue)) %$%
sentiment_by(dialogue_split, list(person))
plot(speaker)
time<-presidential_debates_2012 %>%
dplyr::mutate(dialogue_split = get_sentences(dialogue)) %$%
sentiment_by(dialogue_split, list(time))
plot(time)
plot.emotion(speaker)
debates <- presidential_debates_2012
debates_with_pol <- debates %>%
get_sentences() %>%
sentiment() %>%
mutate(polarity_level = ifelse(sentiment < 0.2, "Negative",
ifelse(sentiment > 0.2, "Positive","Neutral")))
debates_with_pol %>% filter(polarity_level == "Negative") %>% View()
debates_with_senti %>%
ggplot() + geom_boxplot(aes(y = person, x = sentiment))
debates$dialogue %>%
get_sentences() %>%
sentiment_by() %>% #View()
highlight()
debates <- presidential_debates_2012
debates_with_pol <- debates %>%
get_sentences() %>%
sentiment() %>%
mutate(polarity_level = ifelse(sentiment < 0.2, "Negative",
ifelse(sentiment > 0.2, "Positive","Neutral")))
debates_with_pol %>% filter(polarity_level == "Negative") %>% View()
debates_with_pol %>%
ggplot() + geom_boxplot(aes(y = person, x = sentiment))
debates$dialogue %>%
get_sentences() %>%
sentiment_by() %>% #View()
highlight()
debates %>%
get_sentences() %>%
sentiment_by(by = NULL) %>% #View()
ggplot() + geom_density(aes(ave_sentiment))
debates_with_pol <- debates %>%
get_sentences() %>%
sentiment() %>%
mutate(polarity_level = ifelse(sentiment < 0.2, "Negative",
ifelse(sentiment > 0.2, "Positive","Neutral")))
debates_with_pol %>% filter(polarity_level == "Negative") %>% View()
debates_with_pol %>%
ggplot() + geom_boxplot(aes(y = person, x = sentiment))
debates$dialogue %>%
get_sentences() %>%
sentiment_by() %>% #View()
highlight()
debates %>%
get_sentences() %>%
sentiment_by(by = NULL) %>% #View()
ggplot() + geom_density(aes(ave_sentiment))
View(debates_with_pol)
sentiment_attributes(presidential_debates_2012$dialogue)
modifiers<-sentiment_attributes(presidential_debates_2012$dialogue)
View(modifiers)
sentiment_attributes(presidential_debates_2012$dialogue)
profanity(debates)
debates %>%
get_sentences()%>%
profanity()
profanity<-debates %>%
get_sentences()%>%
profanity()
View(profanity)
extract_profanity_terms(debates)
extract_profanity_terms(debates %>% get_sentences())
extract_profanity_terms(get_sentences(debates))
profane_words<-extract_profanity_terms(get_sentences(debates))
View(profane_words)
emotion<-debates %>%
get_sentences()%>%
emotion()
View(emotion)
hist(emotion$emotion_type, emotion$emotion_count)
hist(emotion$emotion_count, emotion$emotion_type)
plot(emotion)
country<-rep(927, times=100000)
mobile1<-rep(50, times=10000)
pick.nums <- function(n){floor(10^(sample(4,n,replace = TRUE))*runif(n))}
random<-pic.nums(100000)
pick.nums <- function(n){floor(10^(sample(4,n,replace = TRUE))*runif(n))}
random<-pic.nums(100000)
random<-pick.nums(100000)
test<-as.data.frame(random)
View(test)
pick.nums <- function(n){floor(10^(sample(4:4,n,replace = TRUE))*runif(n))}
random<-pick.nums(100000)
test<-as.data.frame(random)
View(test)
pick.nums <- function(n){floor(10^(sample(4:4, n ,replace = TRUE))*runif(n))}
random<-pick.nums(100000)
test<-as.data.frame(random)
View(test)
random<-runif(100000, min=1000, max=9999)
test<-as.data.frame(random)
View(test)
random<-floor(runif(100000, min=1000, max=10000))
test<-as.data.frame(random)
View(test)
mobile1<-rep(50, times=20000)
mobile2<-rep(51, times=20000)
mobile3<-rep(52, times=10000)
mobile4<-rep(53, times=10000)
mobile5<-rep(54, times=10000)
mobile6<-rep(55, times=20000)
mobile7<-rep(58, times=10000)
mobile<-rbind(mobile1, mobile2, mobile3, mobile4, mobile5, mobile6, mobile7)
mobile1<-rep(50, times=20000)
mobile2<-rep(51, times=20000)
mobile3<-rep(52, times=10000)
mobile4<-rep(53, times=10000)
mobile5<-rep(54, times=10000)
mobile6<-rep(55, times=20000)
mobile7<-rep(58, times=10000)
mobile<-rbind(mobile1, mobile2, mobile3, mobile4, mobile5, mobile6, mobile7)
mobile1<-rep(50, times=10000)
mobile2<-rep(51, times=10000)
mobile3<-rep(52, times=10000)
mobile4<-rep(53, times=10000)
mobile5<-rep(54, times=10000)
mobile6<-rep(55, times=20000)
mobile7<-rep(58, times=10000)
mobile<-rbind(mobile1, mobile2, mobile3, mobile4, mobile5, mobile6, mobile7)
View(mobile)
mobile<-c(mobile1, mobile2, mobile3, mobile4, mobile5, mobile6, mobile7)
mobile1<-rep(50, times=20000)
mobile2<-rep(51, times=10000)
mobile3<-rep(52, times=10000)
mobile4<-rep(53, times=10000)
mobile5<-rep(54, times=10000)
mobile6<-rep(55, times=20000)
mobile7<-rep(58, times=10000)
mobile<-c(mobile1, mobile2, mobile3, mobile4, mobile5, mobile6, mobile7)
mobile1<-rep(50, times=20000)
mobile2<-rep(51, times=20000)
mobile3<-rep(52, times=10000)
mobile4<-rep(53, times=10000)
mobile5<-rep(54, times=10000)
mobile6<-rep(55, times=20000)
mobile7<-rep(58, times=10000)
mobile<-c(mobile1, mobile2, mobile3, mobile4, mobile5, mobile6, mobile7)
phone_numbers<-as.data.frame(rbind(country, mobile, random))
View(phone_numbers)
View(phone_numbers)
phone_numbers<-as.data.frame(cbind(country, mobile, random))
View(phone_numbers)
phone_numbers<-unique(phone_numbers)
phone_numbers$phone<-paste(phone_numbers$country, phone_numbers$mobile, phone_numbers$random)
View(phone_numbers)
phone_numbers$phone<-paste(phone_numbers$country, phone_numbers$mobile, phone_numbers$random, sep="")
View(phone_numbers)
phone_numbers<-phone_numbers[c("phone")]
write_csv(phone_numbers, "~/Dropbox/israeli_phone_numbers.csv")
write.csv(phone_numbers, "~/Dropbox/israeli_phone_numbers.csv")
phone_numbers$phone<-paste("+", phone_numbers$country, phone_numbers$mobile, phone_numbers$random, sep="")
View(phone_numbers)
phone_numbers<-as.data.frame(cbind(country, mobile, random))
phone_numbers<-unique(phone_numbers)
phone_numbers$phone<-paste("+", phone_numbers$country, phone_numbers$mobile, phone_numbers$random, sep="")
phone_numbers<-phone_numbers[c("phone")]
View(phone_numbers)
write.csv(phone_numbers, "~/Dropbox/israeli_phone_numbers.csv")
install.packages("dialr")
library(dialr)
devtools::install_github("socialresearchcentre/dialr")
devtools::install_github("socialresearchcentre/dialr", update=TRUE)
install.packages("rJava")
library(dialr)
install.packages("JVM")
install.packages("dialr")
library(dialr)
library(rJava)
install.packages("rJava")
brary(rJava)
library(rJava)
library(rJava)
library(dialr)
mobile4<-rep(53, times=10000)
mobile5<-rep(54, times=10000)
mobile6<-rep(55, times=20000)
mobile7<-rep(58, times=10000)
mobile<-c(mobile1, mobile2, mobile3, mobile4, mobile5, mobile6, mobile7)
#Create random 4 digit numbers
set.seed(12345)
random<-floor(runif(100000, min=1000, max=10000))
#Phone NUmbers
phone_numbers<-as.data.frame(cbind(country, mobile, random))
phone_numbers<-unique(phone_numbers)
phone_numbers$phone<-paste("+", phone_numbers$country, phone_numbers$mobile, phone_numbers$random, sep="")
#Load Packages
library(rJava)
library(dialr)
country<-rep(927, times=100000)
mobile1<-rep(50, times=20000)
mobile2<-rep(51, times=20000)
mobile3<-rep(52, times=10000)
mobile4<-rep(53, times=10000)
mobile5<-rep(54, times=10000)
mobile6<-rep(55, times=20000)
mobile7<-rep(58, times=10000)
mobile<-c(mobile1, mobile2, mobile3, mobile4, mobile5, mobile6, mobile7)
#Create random 4 digit numbers
set.seed(12345)
random<-floor(runif(100000, min=1000, max=10000))
#Phone NUmbers
phone_numbers<-as.data.frame(cbind(country, mobile, random))
phone_numbers<-unique(phone_numbers)
phone_numbers$phone<-paste("+", phone_numbers$country, phone_numbers$mobile, phone_numbers$random, sep="")
phone_numbers2<-phone_numbers$phone %>%
list(valid = is_valid,
region = get_region,
type = get_type,
clean = format)
#Lets test phone numbers
library(dplyr)
phone_numbers2<-phone_numbers$phone %>%
list(valid = is_valid,
region = get_region,
type = get_type,
clean = format)
View(phone_numbers2)
valid<-is_valid(phone_numbers$phone)
phone_numbers2<-format(phone_numbers$phone)
valid<-is_valid(phone_numbers2)
phone_numbers2<-format(phone_numbers$phone, strict=TRUE)
test<-as.data.frame(phone_numbers2)
View(test)
valid<-is_valid(phone_numbers2)
phone_numbers2<-phone(phone_numbers$phone, "IL" )
valid<-is_valid(phone_numbers2)
test<-as.data.frame(phone_numbers2)
View(test)
phone_numbers$phone<-paste(phone_numbers$country, phone_numbers$mobile, phone_numbers$random, sep="")
phone_numbers2<-phone(phone_numbers$phone, "IL" )
valid<-is_valid(phone_numbers2)
table(valid)
phone_numbers2<-phone(phone_numbers$phone, "ISR" )
phone_numbers2<-phone(phone_numbers$phone)
phone_numbers2<-phone(phone_numbers$phone, region="IL")
get_cc("Israel")
ph_example("IL", type = "MOBILE")
get_example("IL", type = "MOBILE")
country<-rep(927, times=100000)
mobile1<-rep(50, times=20000)
mobile2<-rep(51, times=20000)
mobile3<-rep(52, times=10000)
mobile4<-rep(53, times=10000)
mobile5<-rep(54, times=10000)
mobile6<-rep(55, times=20000)
mobile7<-rep(58, times=10000)
mobile<-c(mobile1, mobile2, mobile3, mobile4, mobile5, mobile6, mobile7)
#Create random 7 digit numbers
set.seed(12345)
random<-floor(runif(100000, min=1000000, max=10000000))
#Phone NUmbers
phone_numbers<-as.data.frame(cbind(country, mobile, random))
phone_numbers<-unique(phone_numbers)
phone_numbers$phone<-paste("+",phone_numbers$country, phone_numbers$mobile, phone_numbers$random, sep="")
phone_numbers2<-phone(phone_numbers$phone, region="IL")
valid<-is_valid(phone_numbers2)
table(valid)
View(phone_numbers)
get_example("IL", type = "MOBILE")
country<-rep(972, times=100000)
mobile1<-rep(50, times=20000)
mobile2<-rep(51, times=20000)
mobile3<-rep(52, times=10000)
mobile4<-rep(53, times=10000)
mobile5<-rep(54, times=10000)
mobile6<-rep(55, times=20000)
mobile7<-rep(58, times=10000)
mobile<-c(mobile1, mobile2, mobile3, mobile4, mobile5, mobile6, mobile7)
#Create random 7 digit numbers
set.seed(12345)
random<-floor(runif(100000, min=1000000, max=10000000))
#Phone NUmbers
phone_numbers<-as.data.frame(cbind(country, mobile, random))
phone_numbers<-unique(phone_numbers)
phone_numbers$phone<-paste("+",phone_numbers$country, phone_numbers$mobile, phone_numbers$random, sep="")
#phone_numbers<-phone_numbers[c("phone")]
#write.csv(phone_numbers, "~/Dropbox/israeli_phone_numbers.csv")
#Lets test phone numbers
library(dplyr)
get_example("IL", type = "MOBILE")
get_cc("Israel")
phone_numbers2<-phone(phone_numbers$phone, region="IL")
valid<-is_valid(phone_numbers2)
table(valid)
valid2<-cbind(phone_numbers$phone, valid)
View(valid2)
type<-type(phone_numbers2)
ph_type<-type(phone_numbers2)
type<-ph_type(phone_numbers2)
type<-ph_type(phone_numbers2, country="IL")
type<-get_type(phone_numbers2, region="IL")
type<-get_type(phone_numbers2)
table(type)
table(valid)
valid_numbers<-subset(valid2, valid==TRUE)
View(valid_numbers)
test<-unique(valid_numbers)
write.csv(valid_numbers, "~/Dropbox/israeli_phone_numbers.csv")
#Load Packages
library(readr)
library(dplyr)
require(viridis)
library(geometry)
library(sf)
library(maps)
library(mapdata)
library(mapview)
#Set Working Directory
setwd("~/Dropbox/egypt_tolerance_wp_replication/")
#Read in location data
data<-read_csv("data/egypt_geo.csv")
data$count<-1
locations_count<-data %>%
group_by(lat, lng) %>%
summarise(freq=sum(count))
locations_sf <- st_as_sf(locations_count, coords = c("lng", "lat"))
world = spData::world
data<-na.omit(data)
data$count<-1
locations_count<-data %>%
group_by(lat, lng) %>%
summarise(freq=sum(count))
locations_sf <- st_as_sf(locations_count, coords = c("lng", "lat"))
world = spData::world
mapviewOptions(basemaps = c("Esri.WorldShadedRelief", "OpenStreetMap.DE", "CartoDB.Positron", "CartoDB.VoyagerNoLabels", "CartoDB.Voyager"),
raster.palette = grey.colors,
vector.palette = colorRampPalette(c("black", "black", "black")),
na.color = "magenta",
layers.control.pos = "topright")
mapview(world)+
mapview(locations_sf, cex="freq", legend=FALSE, color="black")
mapviewOptions(basemaps = c("Esri.WorldShadedRelief", "OpenStreetMap.DE", "CartoDB.Positron", "CartoDB.VoyagerNoLabels", "CartoDB.Voyager"),
raster.palette = grey.colors,
vector.palette = colorRampPalette(c("black", "black", "black")),
na.color = "white",
layers.control.pos = "topright")
mapview(world)+
mapview(locations_sf, cex="freq", legend=FALSE, color="black")
